package com.chandankumar.gaejsimplesite.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.chandankumar.gaejsimplesite.gae.db.PageService;
import com.chandankumar.gaejsimplesite.model.Page;

@Controller
public class PageViewController {
	protected final Log logger = LogFactory.getLog(getClass());
	@Autowired
    private PageService pageService;
    @RequestMapping(value="/p/{key}", method=RequestMethod.GET)
    public String index(@PathVariable String key, Model model){
    	Page page = pageService.findByKey(Long.valueOf(key));
    	if(page==null){
    		return "common/404";
    	}
		model.addAttribute("page", page);
		return "page/view";
	}

}
